interface name { Final Data members ------- Abstract methods ------ }
interface Solid { public void printvolume(); } interface Surface { public void printarea(); } class Rectangle implements Surface { private int L,B; public Rectangle(int m,int n) { L=m; B=n; } public void printarea() { int a=L*B; System.out.println("Area is "+a); } } class Circle implements Surface { private int r; public Circle(int n) { r=n; } public void printarea() { double a=3.14*r*r; System.out.println("Area is "+a); } } class Box implements Solid, Surface { private int L,B,H; public Box(int x,int y,int z) { L=x; B=y; H=z; } public void printvolume() { int v=L*B*H; System.out.println("Volume is "+v); } public void printarea( ) { int a=2*L*H+2*B*H+2*L+B; System.out.println("Area is "+a); } } class demo { public static void main(String args[]) { Circle a=new Circle(5); Rectangle b=new Rectangle(10,20); Box c=new Box(2,3,4); a.printarea(); b.printarea(); c.printarea(); c.printvolumne(); } }
Area is 78.5 Area is 200 Area is 47 Volume is 24